<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<link href="style/jquery_ui/jquery-ui-1.8.custom.css" rel="stylesheet"
			type="text/css" />
		<link id="skin_css" rel="stylesheet" type="text/css"
			href="themes/css/ui.c.blue.css"></link>
		<link rel="stylesheet" href="themes/default/pagination.css"
			type="text/css"></link>
		<link rel="stylesheet" href="themes/css/ui.validation.css" type="text/css"></link>
		<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>

		<script src="Scripts/ui.tips.js" type="text/javascript"></script>
		<script src="Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<script src="Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script src="js/ui.editableObject.js" type="text/javascript"></script>
		<script src="js/goodsOrderHandler.js" type="text/javascript"></script>
		<script src="js/bussiness.goodsReturn.js" type="text/javascript"></script>
		<script type="text/javascript" src="Scripts/jquery.json-2.2.min.js"></script>
		<STYLE type="text/css">
		.editorArea {
		display: none;
		}
		</STYLE>
		<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
		<script type="text/javascript" src="Scripts/ui.validation.js"></script>
		<SCRIPT type="text/javascript">
			$(function(){
				$("#dialog").dialog("destroy"); 
				$("#dialog-form").dialog({
				autoOpen: false,
				height: 300,
				width: 550,
				modal: true,
				 
				close: function() {
					//allFields.val('').removeClass('ui-state-error');
				}
				});
				
				$('#addSectionButton').click(function() {   
						$("#dialog-form").dialog({'title':"添加 部门信息"});
					clearInputControlValue("#dialog-form");
				     $('#dialog-form').dialog('open'); 
				});
	            registeTabToggle("#addSectionCategoryButton", "#cancelAddSectionCategoryButton");
	            //注册功能按钮事件..
	            registeRowFuncButton();
	            setValidate();    
			    });
			    
			   function setValidate(){
    
    	 		$("#form").validatingForm({
        		submitButtonId:"#btnSubmit",
        	  	clearErrorsOnFocus:true,
        	 	validateOnBlur:true,
        	 	success:submit
        		});
    		}
			//单击编辑按钮的时候,进行编辑, 
				//该模块中,需要在弹出层中编辑,因此可以在这里对弹出层上的表单控件进行赋值,
				//之后调用 最后一行代码显示弹出层..
				//如果不需要在弹出层进行编辑,可以直接在编辑按钮的 href 里面执行action 跳转..etc..
				//
				
				// 参数 e 包含两个属性:
				//			data ---> 所单击行的数据(一个数组)
				//			entityId ---> 对应 对象的 ID
				function toEditHandler(e)
				{ 
				    var columns = e.data;
					$("#dialog-form").dialog({'title':"编辑  部门信息"});
					$("#txt_sectionNo").val($(columns[3]).text());
					$("#txt_sectionName").val($(columns[2]).text());
					var sectionCategoryId =  $(columns[4]).find(".sectionCategory").attr("categoryId");
					$("#drl_sectionType").val(sectionCategoryId );
					var sectionId = $(columns[5]).find(".sectionInfo").attr("sectionId");
					$("#sectionId").val(e.entityId);
				
					$('#dialog-form').dialog('open'); 
				}
				
				function toDeleteHandler(e)
				{
			   	 var sectionId = e.entityId;
			     location="sectionInfo!delete.action?sectionIds="+sectionId;
				}
				
				function checkAll(str)
				{
 					var items = document.getElementsByName(str); //获取所有复选框
					var totalNum = items.length; //获取复选框的个数
					for (var i=0; i<totalNum; i++)
					items[i].checked = window.event.srcElement.checked;//通过单击的按钮判断是选中还是未选
				}
				
				function deleteAll(str)
				{
					var isTo = checkDeleteAll("部门信息记录");

					if(isTo==false)
  					return ;
 					var items = document.getElementsByName(str); //获取所有复选框
					var totalNum = items.length; //获取复选框的个数
					var delStr = "";
					for (var i=0; i<totalNum; i++){
						if(items[i].checked == true){
							delStr += items[i].value + ","; 
						}
					}
					delStr = delStr.substring(0, delStr.length -1);
					location.href="sectionInfo!delete.action?sectionIds="+delStr;
				}
				
				function submit(){
					var sectionInfo = {
					"sectionId": $.trim($("#sectionId").val()),
					"sectionNo": $.trim($("#txt_sectionNo").val()),
					"sectionName":$.trim($("#txt_sectionName").val()),
					"sectionCategoryId":$.trim($("#drl_sectionType").val())
					};
				
					var jsonString = $.toJSON(sectionInfo);
					//alert(jsonString);
					$.post(
					"sectionInfo!add.action",
					{
						sectionInfoJsonString: jsonString
					},
					function(data){
						if(data == "1"){
							alert("提示:操作成功！");
							location="sectionInfo.action";
						}
						if(data == "-1"){
							alert("错误:操作失败！");
							return;
						}
					},
					"json"
					);
				}
				
				function submitAddCategory(){
					var sectionCategoryInfo = {
					"categoryName": $.trim($("#txt_categoryName").val())
					} ;
				
					var jsonString = $.toJSON(sectionCategoryInfo);

					$.post(
					"sectionInfo!addCategory.action",
					{
						sectionInfoJsonString: jsonString
					},
					function(data){
						location="sectionInfo.action";
					},
					"json"
					);
				}
				
			</script>
	</head>
	<body>
		<div class="PageChild_Title">
			<img src=" themes/images/default/icons/archives.png"
				class="PageChild_Tbtnpic" />
			<span class="PageChild_separate"></span>
			<span class="PageChild_TbtnText"><h2>
					部门信息
				</h2>
			</span>
			<span class="PageChild_separate"></span>
			<div id="marker" class="red-tips">
			</div>
			<div class="clear">
			</div>
		</div>
		<div class="PageChild_Where">
			<table style="height: 60px;" border="0" cellpadding="0"
				cellspacing="0">
				<tr>
					<td>
						&nbsp;&nbsp;
					</td>
					<td>
						<span id="lbl_list_count">共搜索到 <b>${count}</b> 条符合条件的记录。</span>
						<input type="button" id="addSectionButton"
							class="o-btn SubmitButton" value="添加部门" />
					</td>
				</tr>
			</table>
		</div>
		<div class="PageChild_List">
			<table width="100%" border="0" cellspacing="0"
				style="text-align: left">
				<tbody class="PageChild_List_head">
					<tr>
						<td width="16">
							<input id="Chk_All" type="checkbox" name="Chk_All"
								onclick="checkAll('Chk_Num')" />
						</td>
						<td width="16">
							<img src="themes/images/default/icons/pcde_314.png" width="16"
								height="16" />
						</td>
						<td>
							部门名称
						</td>
						<td>
							部门编号
						</td>
						<td>
							部门类别
						</td>
						<td class="td_width40">
							编辑
						</td>
						<td class="td_width40">
							删除
						</td>
						<td class="td_width40">
							状态
						</td>
					</tr>
				</tbody>
				<tbody class="PageChild_List_main" style="text-align: left">
					<s:if test="allInfoList != null && allInfoList.size != 0">
					<s:iterator value="allInfoList" var="item" status="no">
						<tr class='td_no_bord'>
							<td class="td_width25">
								<span title="24"><input id="Chk_Num" type="checkbox"
										name="ReptShow$ctl01$Chk_Num" value="${item.sectionId}" /> </span>
							</td>
							<td class="td_width25">
								<s:property value="#no.count" />
							</td>
							<td>
								<span>${item.sectionName} </span>&nbsp;
							</td>
							<td>
								${item.sectionNo}&nbsp;
							</td>
							<td>
								<span class="sectionCategory"
									categoryId="${item.sectionCategory.categoryId}">${item.sectionCategory.categoryName}
								</span>&nbsp;
							</td>
							<td>
								<a class="ui-link-edit-button" id="sender_${item.sectionId}"
									href="javascript:void(0);" state="0"
									entityId="${item.sectionId}"> <img
										src="themes/icons/edit.png" title="进行编辑" /> </a> &nbsp;
							</td>
							<td>
								<a href="javascript:;" class="ui-link-delete-button"
									entityId="${item.sectionId}" onclick=''><img
										src="themes/icons/delete.png" /> </a>
							</td>
							<td>
								<s:if test="#item.states==0">
									<a href="javascript:;"
										onclick='location="sectionInfo!toEnable.action?sectionId=${item.sectionId}"'><img
											src=" themes/icons/btn_disable.png" /> </a>
								</s:if>
								<s:if test="#item.states==1">
									<a href="javascript:;"
										onclick='location="sectionInfo!toDisable.action?sectionId=${item.sectionId}"'><img
											src=" themes/icons/btn_enable.png" /> </a>
								</s:if>
							</td>
						</tr>
					</s:iterator>
					</s:if><s:else>
						<tr><td colspan="9">无记录</td></tr>
					</s:else>
				</tbody>
			</table>

		</div>
		<div>
			<input type="button" name="btn_Delete" class="o-btn SubmitButton"
				value="删 除" id="btn_Delete"
				onclick="deleteAll('ReptShow$ctl01$Chk_Num')">
		</div>
	</body>

	<!-- 弹出层标签 -->
	<div id="dialog-form" style="display: none;" title="添加新部门">
		<div class="ui-mainTab">
			<form id="form" action="">
			<div><input type="text" id="sectionId" class="hiddenObject clearable" />
				<table width="100%" class="tb tb2">
					<tr>
						<td class="mtd">
							&nbsp;部门类别:
						</td>
						<td>
							<s:select list="categoryList" listKey="categoryId" listValue="categoryName" headerKey="-1" headerValue="-请选择-" theme="simple" emptyValueMsg="请选择部门类别。" emptyValueForValidate="-1" cssClass="control selectable-field clearable" id="drl_sectionType" />
							<input type="button" id="addSectionCategoryButton" value="添加" class="o-btn SubmitButton">
						</td>
					</tr>
					<tr>
						<td class="mtd">
							部门编号:
						</td>
						<td>
							<input class="control required-field clearable" type="text" value=""
								id="txt_sectionNo">
						</td>
					</tr>
					<tr>
						<td class="mtd">
							部门名称:
						</td>
						<td>
							<input class="control required-field clearable" type="text" id="txt_sectionName">
						</td>
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							<div>
								<input id="btnSubmit" type="button" value="提 交" class="o-btn SubmitButton">
								&nbsp;
								<input type="button" name="name" id="cancelAddGoodsInfoButton"
									class="dialogFormCloseButton o-btn" dialogForm="#dialog-form"
									value="关闭" />
							</div>
						</td>
					</tr>
				</table>
			</div>
			</form>
		</div>

		<!-- 弹出层结束 -->

		<div id="addGoodsCategoryTab" title="添加部门类型" class="ui-assistantTab"
			style="display: none;">
			<table width="100%" class="tb tb2">
				<tbody>
					<tr>
						<td class="mtd">
							<br />
							部门类型:
						</td>
						<td>
							<input class="control clearable" type="text" id="txt_categoryName" />
						</td>
						<td width="20">
						</td>
					</tr>
				</tbody>
				<tr>
					<td class="mtd">
						&nbsp;
					</td>
					<td>
						<input type="button" name="name" value="添 加"
							class="o-btn SubmitButton" onclick='var text= $("#txt_categoryName").val();if($.trim(text).length==0){alert("请输入名称.");$("#txt_categoryName").focus(); return false;} submitAddCategory();'/>
						<input type="button" name="name"
							id="cancelAddSectionCategoryButton" value="取 消"
							class="o-btn SubmitButton" />
					</td>
					<td></td>
				</tr>
			</table>
		</div>
	</div>
</html>
